package com.ruoyi.teaching.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.teaching.domain.YaCourseDesignDetail;
import com.ruoyi.teaching.service.IYaCourseDesignDetailService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 课程设计详情Controller
 *
 * @author ruoyi
 * @date 2025-03-15
 */
@RestController
@RequestMapping("/course_design_detail")
public class YaCourseDesignDetailController extends BaseController
{
    @Autowired
    private IYaCourseDesignDetailService yaCourseDesignDetailService;

    @RequiresPermissions("teaching:course_design_detail:query")
    @GetMapping
    public AjaxResult getCourseDisignDetailList(@RequestParam("courseId") Long courseId,@RequestParam("stage") Long stage)
    {
        YaCourseDesignDetail yaCourseDesignDetail = new YaCourseDesignDetail();
        yaCourseDesignDetail.setCourseId(courseId);
        yaCourseDesignDetail.setStage(stage);
        return success(yaCourseDesignDetailService.selectYaCourseDesignDetailList(yaCourseDesignDetail));
    }

    /**
     * 保存关联面试题
     */
    @RequiresPermissions("teaching:course_design_detail:edit")
    @Log(title = "课程设计", businessType = BusinessType.UPDATE)
    @PutMapping("/related_interview/{cdId}")
    public AjaxResult editRelatedInterview(@PathVariable("cdId")Integer cdId,@RequestBody List<Integer> interviewIdList)
    {
        return toAjax(yaCourseDesignDetailService.editRelatedInterview(cdId,interviewIdList));
    }
    /**
     * 查询课程设计详情列表
     */
    @RequiresPermissions("teaching:course_design_detail:list")
    @GetMapping("/list")
    public TableDataInfo list(YaCourseDesignDetail yaCourseDesignDetail)
    {
        startPage();
        List<YaCourseDesignDetail> list = yaCourseDesignDetailService.selectYaCourseDesignDetailList(yaCourseDesignDetail);
        return getDataTable(list);
    }

    /**
     * 导出课程设计详情列表
     */
    @RequiresPermissions("teaching:course_design_detail:export")
    @Log(title = "课程设计详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YaCourseDesignDetail yaCourseDesignDetail)
    {
        List<YaCourseDesignDetail> list = yaCourseDesignDetailService.selectYaCourseDesignDetailList(yaCourseDesignDetail);
        ExcelUtil<YaCourseDesignDetail> util = new ExcelUtil<YaCourseDesignDetail>(YaCourseDesignDetail.class);
        util.exportExcel(response, list, "课程设计详情数据");
    }

    /**
     * 获取课程设计详情详细信息
     */
    @RequiresPermissions("teaching:course_design_detail:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(yaCourseDesignDetailService.selectYaCourseDesignDetailById(id));
    }

    /**
     * 新增课程设计详情
     */
    @RequiresPermissions("teaching:course_design_detail:add")
    @Log(title = "课程设计详情", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YaCourseDesignDetail yaCourseDesignDetail)
    {
        return toAjax(yaCourseDesignDetailService.insertYaCourseDesignDetail(yaCourseDesignDetail));
    }

    /**
     * 修改课程设计详情
     */
    @RequiresPermissions("teaching:course_design_detail:edit")
    @Log(title = "课程设计详情", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YaCourseDesignDetail yaCourseDesignDetail)
    {
        return toAjax(yaCourseDesignDetailService.updateYaCourseDesignDetail(yaCourseDesignDetail));
    }

    /**
     * 删除课程设计详情
     */
    @RequiresPermissions("teaching:course_design_detail:remove")
    @Log(title = "课程设计详情", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(yaCourseDesignDetailService.deleteYaCourseDesignDetailByIds(ids));
    }
}
